package com.example.parsexml;
import android.util.Log;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
 * project:
 * author: wzq
 * date: 2014/7/31
 * description:
 */
public class Sax {
    public static List<ModelStu> parse(InputStream is) {
        try {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            // SAXParserFactory.newInstance().newSAXParser();
            SaxHandler dataHandler = new SaxHandler();
            sp.parse(is, dataHandler);

            List<ModelStu> stuList = dataHandler.getData();
            return stuList;
        } catch(ParserConfigurationException pce) {
            Log.e("SAX XML", "sax parse error", pce);
        } catch(SAXException se) {
            Log.e("SAX XML", "sax error", se);
        } catch(IOException ioe) {
            Log.e("SAX XML", "sax parse io error", ioe);
        }
        return null;
    }
}
